﻿using MVCScaffolder.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MVCScaffolder
{
    public class CreateCSHtml
    {
        public CreateCSHtml(CodeGeneratorProperty CodeGeneratorProperties)
        {
            //****** Move to T4 *******//
            SpaceStackStringBuilder sb = new SpaceStackStringBuilder();

            if (CodeGeneratorProperties.UsingDropDownLists)
            {
                sb.AppendLine("@model " + CodeGeneratorProperties.NamespaceName + ".Models." + CodeGeneratorProperties.PropertyClassName + "CreateOrEdit");
            }
            else
            {
                sb.AppendLine("@model " + CodeGeneratorProperties.NamespaceName + "." + CodeGeneratorProperties.PropertyClassName);
            }

            sb.AppendLine();
            sb.AppendLine("@{");
            sb.AppendLine(@"    ViewBag.Title = ""Create"";");
            sb.AppendLine("}");
            sb.AppendLine();
            sb.AppendLine("<h2>Create</h2>");
            sb.AppendLine("");
            sb.AppendLine("@using (Html.BeginForm()) {");
            if (true)
            {
                sb.AddSpace();
                sb.AppendLine("@Html.ValidationSummary(true)");
                sb.AppendLine("<fieldset>");
                if (true)
                {
                    sb.AddSpace();
                    sb.AppendLine("<legend>" + CodeGeneratorProperties.PropertyClassName + "</legend>");
                    sb.AppendLine("");
                    sb.AppendLine(@"@Html.Partial(""_CreateOrEdit"", Model)");
                    sb.AppendLine("");
                    sb.AppendLine("<p>");
                    if (true)
                    {
                        sb.AddSpace();
                        sb.AppendLine(@"<input type=""submit"" value=""Create"" />");
                        sb.RemoveSpace();
                    }
                    sb.AppendLine("</p>");
                    sb.RemoveSpace();
                }
                sb.AppendLine("</fieldset>");
                sb.RemoveSpace();
            }
            sb.AppendLine("}");
            sb.AppendLine("");
            sb.AppendLine("<div>");
            if (true)
            {
                sb.AddSpace();
                sb.AppendLine(@"@Html.ActionLink(""Back to List"", ""Index"")");
                sb.RemoveSpace();
            }
            sb.AppendLine("</div>");

            WriteLine(sb.ToString());
            //****** Move to T4 *******//

        }

        String Text = "";
        public void WriteLine(String s)
        {
            Text = s.ToString();
        }

        public override string ToString()
        {
            return Text;
        }
    }
}
